#include "stdafx.h"
#include "jlistmodel.h"

JListModel::JListModel(JTablePtr tb):
    m_table(tb),wxDataViewVirtualListModel(tb->GetRowCount())
{

}

unsigned int JListModel::GetColumnCount() const
{
    return m_table->GetColumnCount();
}

wxString JListModel::GetColumnType(unsigned int col) const
{
    return wxT("string");
}

void JListModel::GetValueByRow(wxVariant &variant, unsigned int row, unsigned int col) const
{
    variant=m_table->getCell(row,col);
}

bool JListModel::GetAttrByRow(unsigned int row, unsigned int col, wxDataViewItemAttr &attr) const
{

    if(row%2==0)
    {
        attr.SetBackgroundColour(wxColour(220,220,220));
    }else {
        attr.SetBackgroundColour(wxColour(255,255,255));
    }

    return true;
}

bool JListModel::SetValueByRow(const wxVariant &variant, unsigned int row, unsigned int col)
{
    if(row<m_table->GetRowCount() && col<m_table->GetColumnCount())
    {
        m_table->setCell(row,col,variant);
        return true;
    }else {
        return false;
    }
}



JListModel::JListModel()
{

}
